package com.inspector.app.ui.task

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asFlow
import androidx.lifecycle.asLiveData
import com.inspector.app.ui.vo.Params
import com.inspector.app.ui.vo.TaskData
import com.inspector.app.ui.vo.TaskItem
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf

class TaskViewModel(private val repos: TaskRepository) : ViewModel() {

    val systemTaskPosition = MutableLiveData(Params().apply {
        systemTaskPos = true
    })

    @OptIn(ExperimentalCoroutinesApi::class)
    fun getItems(): LiveData<TaskData> {
        return systemTaskPosition.asFlow().flatMapLatest { item ->
            repos.getTaskItems(item)
        }.asLiveData()
    }

}
